Custom Domains: Map our Domain to Load Balancers

Objective#

  • Access our application from a custom domain.

Steps#

  • Map our domain to the load balancers.

Creating a DNS record per stage#

Let’s start by adding two new input parameters in our stage.yml to receive the stage domain and subdomain.

stage.yml

Then, let’s add a resource to create a Route 53 A record that points <subdomain>.<domain> to the load balancer.

stage.yml

Next, let’s change the stage output to return the URL with our custom domain rather than the load balancer’s default endpoint.

stage.yml

Then we also need to add an input parameter in main.yml to receive our custom domain name.

main.yml

And finally, we need to pass our custom domain to the nested stacks.

main.yml

Line #9 and #20: Passes the domain name to the nested stack.

Line #10 and #21: Passes a stack-specific subdomain to the nested stack.

At this point, let’s add our domain name as an environment variable at the top of deploy-infra.sh.

deploy-infra.sh

Line #1: Replace with your domain name.

And now we can pass our domain to the CloudFormation template.

deploy-infra.sh

Line #12: Passes the domain name to main.yml.

Let’s deploy to see our custom domain in action.

terminal

And now have a much more human-friendly endpoint for our two stages. We should also be able to see the A records in our Route 53 hosted zone.

New A Records
New A Records

The DNS propagation can take a few minutes. After a while, we should be able to reach our application through our custom domain.

terminal
terminal

🔍 If the curl commands work, but your browser times out trying to connect, it may be trying to upgrade to HTTPS in order to provide better security. You can try from another browser or wait until we enable HTTPS in the next section.

Now we can commit all our changes to checkpoint our progress.

terminal

Note: All the code has been already added and we are pushing it on our repository as well.

Please provide values for the following:
username
Not Specified...
AWS_ACCESS_KEY_ID
Not Specified...
AWS_SECRET_ACCESS_KEY
Not Specified...
AWS_REGION
us-east-1
Github_Token
Not Specified...
/
package.json
stage.yml
server.js
main.yml
github.sh
setup.yml
deploy-infra.sh
stop-service.sh
start-service.sh
buildspec.yml
appspec.yml

In order to get a pictorial view of our developed cloudformation stack so far, below is the design view which shows the resources we created and their relationships.

Custom Domain
Custom Domain

In the next lesson, we will migrate our endpoint from HTTP to HTTPS.

Custom Domains: Register Domain with Route 53
HTTPS: Create a TLS Certificate
Mark as Completed
Report an Issue